package com.qianzhou.eduWeb.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qianzhou.eduService.service.CourseService;
import com.qianzhou.vo.CourseVO;
import com.qianzhou.vo.ResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 描述：CourseController 课程接口
 */
@Slf4j
@RestController
@RequestMapping("course")
@Api(tags = {"课程接口"})
public class CourseController {
    @Reference
    private CourseService courseService;

    @ApiOperation("获取所有的课程信息")
    @RequestMapping(value = "getAllCourse", method = {RequestMethod.GET})
    public ResponseVO<Object> getAllCourse() {
        List<CourseVO> courseVOS = courseService.getAllCourse();
        log.info(courseVOS.toString());
        return new ResponseVO<>(2000, "响应成功", courseVOS);
    }

    @ApiOperation("查看已购课程")
    @RequestMapping(value = "getCourseByUserId/{id}", method = {RequestMethod.GET})
    public ResponseVO<Object> getCourseByUserId(@PathVariable("id") Integer id) {
        List<CourseVO> courseVOS = courseService.getCourseByUserId(id);
        return new ResponseVO<>(2000, "响应成功", courseVOS);
    }

    @ApiOperation("根据课程id查询课程信息")
    @RequestMapping(value = "getCourseById/{courseId}", method = {RequestMethod.GET})
    public ResponseVO<Object> getCourseById(@PathVariable("courseId") Integer courseId) {
        CourseVO courseVO = courseService.getCourseById(courseId);
        return new ResponseVO<>(2000, "响应成功", courseVO);
    }
}
